using System;
using System.Data;
using Gtk;
using Npgsql;


public partial class MainWindow : Gtk.Window
{
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		
		string connectionString = "Server=localhost; Database=dbprueba; User ID=dbprueba; Password=sistemas";
		NpgsqlConnection dbConnection = new NpgsqlConnection(connectionString);
		dbConnection.Open();
		
		DataSet dataSet = new DataSet();
		
		IDataAdapter dataAdapter = new NpgsqlDataAdapter("SELECT * FROM articulo", dbConnection);
		
		dataAdapter.Fill(dataSet);
		showDataSet(dataSet);
		
		dbConnection.Close();
	}
	
	private void showDataSet (DataSet dataSet){
		foreach (DataTable dataTable in dataSet.Tables){
			showDataTable(dataTable);		
		}
	}
	
	private void showDataTable (DataTable dataTable){
		foreach (DataRow dataRow in dataTable.Rows){
			showDataRow(dataRow);		
		}
	}
	
	private void showDataRow (DataRow dataRow){
		foreach (DataColumn dataColumn in dataRow.Table.Columns){
			Console.WriteLine("{0} = {1}", dataColumn.ColumnName, dataRow[dataColumn]);		
		}
	}

	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
}
